<template>
	<view class="OuterBg">
		<navbar title="推荐返利" :immersive="false" :background="navbackg" :titleColor="'#fff'"></navbar>
		<rhead :dindex="1"></rhead>
		<template v-if="lookUp">
			<!-- income -->
			<view class="OuterBox">
				<view class="accumulate" v-if="Detainfo">
					<view class="tit">{{$zhTran('累计收益')}}</view>
					<view class="num style1">
						{{Detainfo.rebate_amount || '0'}}
					</view>
					<view class="time">
						{{$zhTran('数据截止')}}{{Detainfo.last_time || ''}}
					</view>

					<view class="tixian FlexRow" @click="tixian">
						{{$zhTran('去提现')}}
						<i class="iconfont icon-imore"></i>
					</view>
				</view>

				<view class="accuDatainfor FlexBetween">
					<view class="infor_item FlexColumn FlexItem">
						<view class="num">
							{{Detainfo.day_profit || '0'}}
						</view>
						<view class="tit">
							{{$zhTran('日收益')}}
						</view>
					</view>
					<view class="infor_item FlexColumn FlexItem">
						<view class="num">
							{{Detainfo.month_profit || '0'}}
						</view>
						<view class="tit">
							{{$zhTran('月收益')}}
						</view>
					</view>
					<view class="infor_item FlexColumn FlexItem">
						<view class="num">
							{{Detainfo.year_profit || '0'}}
						</view>
						<view class="tit">
							{{$zhTran('年收益')}}
						</view>
					</view>
					<view class="infor_item FlexColumn FlexItem">
						<view class="num">
							{{Detainfo.rebate_amount || '0'}}
						</view>
						<view class="tit">
							{{$zhTran('全部收益')}}
						</view>
					</view>
				</view>

				<view class="detail_tit">
					{{$zhTran('收益明细')}}
				</view>
				<view class="datalist" v-if="pageobj.list.length">
					<view class="data_val detail_item FlexBetween" v-for="(item, index) in pageobj.list">

						<view class="detail_left">
							<view class="tit Singlerow">
								{{item.activity.sn || ''}}
							</view>
							<view class="txt Singlerow">
								{{$zhTran('购买商品')}}：{{item.activity.goods_name || ''}}
							</view>
							<view class="time">
								{{item.create_time || ''}}
							</view>
						</view>
						<view class="detail_right">
							<view class="prices">
								{{item.change_amount || '0'}}
							</view>
							<!-- <view class="user_info FlexAlign">
								<view class="icon">
									<image :src="$getImageUri(item.user_avatar)" mode="widthFix"></image>
								</view>
								<view class="tname">
									{{item.user_nickname || ''}}
								</view>
							</view> -->
						</view>
					</view>
				</view>
			</view>
		</template>

	</view>
</template>

<script>
	import rhead from "./components/rhead.vue";

	import {
		apiprofitLists,
		apirofitDetai,
	} from '@/api/rebate'
	export default {
		components: {
			rhead,
		},
		created() {
			this.getDatasList()
			this.getofitDetai()
		},
		onShow() {

		},
		// 触底
		onReachBottom() {
			if (this.pageobj.page_size > 10) {
				this.pageobj.page_no = Math.ceil(this.pageobj.page_size / 10)
				this.pageobj.page_size = 10
			}
			if (this.pageobj.page_total > this.pageobj.page_no) {
				this.pageobj.page_no += 1
				this.getDatasList()
			} else {
				if (this.pageobj.list.length) {
					uni.showToast({
						title: this.$zhTran('到底了'),
						icon: 'none',
						duration: 2000,
					})
				}
			}
		},
		methods: {

			tixian() {
				uni.navigateTo({
					url: '/bundle/pages/user_withdraw/user_withdraw',
				})
			},
			// 列表重置
			ResetRefresh() {
				this.pageobj.page_no = 1
				this.pageobj.page_size = 10
				this.pageobj.page_total = 0
				this.pageobj.list = []
				this.pageobj.initial = true
				this.getDatasList()
			},
			// 原地页面刷新 数据变动
			InsituRefresh() {
				this.pageobj.page_size = this.pageobj.page_size * this.pageobj.page_no
				this.pageobj.page_no = 1
				this.page_total = 0
				this.pageobj.initial = true
				this.getDatasList()
			},
			// 获取列表数据
			async getDatasList() {

				let data = {
					page_no: this.pageobj.page_no, //	Integer	必填，非空	页码，默认1
					page_size: this.pageobj.page_size, //	Integer	必填，非空	每页显示，默认10
				}
				apiprofitLists(data).then((res) => {
					this.handleDatas(this.$zhTran(res))
				}).catch(err => {

				})
			},
			getofitDetai() {

				apirofitDetai().then((res) => {
					console.log(res, 'apirofitDetai')
					// rebate_amount	Decimal	累计收益/全部收益
					// day_profit	Decimal	日收益
					// month_profit	Decimal	月收益
					// year_profit	Decimal	年收益
					// last_time	String	截至时间
					this.Detainfo = this.$zhTran(res)
				}).catch(err => {

				})
			},
			// 处理列表数据
			handleDatas(resobj) {
				if (!resobj) return;
				let {
					count,
					lists,
					extend,
				} = resobj
				let {
					page_size,
					initial
				} = this.pageobj
				for (let item of lists) {
					if (!initial) {
						this.pageobj.list.push(item)
					}
				}
				if (initial) { // 初次加载
					this.pageobj.page_total = Math.ceil(count / page_size)
					this.pageobj.list = lists
					this.pageobj.initial = false

				}
			},
		},
		data() {
			return {
				Detainfo: '',
				navbackg: {
					'background': 'rgba(64, 115, 250, 1)'
				},
				lookUp: true,
				pageobj: {
					page_no: 1, // 当前第几页
					page_size: 10, // 一页多少数据
					page_total: 0,
					initial: true, // 是否为第一次加载数据
					list: [],
				},
			}
		},
	}
</script>

<style lang="scss" scoped>
	@import "./css/tlist.scss";

	.OuterBox::after {
		content: '';
		display: block;
		position: absolute;
		width: 100%;
		height: 122rpx;
		background: rgba(64, 115, 250, 1);
		top: 0;
		left: 0;
		z-index: 1;
	}

	.accumulate {
		z-index: 2;
		position: relative;
		width: 100%;
		height: 260rpx;
		border-radius: 14rpx;
		background: url(./img/accumbg.png) no-repeat;
		background-size: cover;
		padding: 40rpx 0 0 46rpx;

		.tit {
			font-size: 32rpx;
			font-weight: 400;
			color: rgba(22, 22, 22, 1);
			text-align: left;
			vertical-align: top;
		}

		.num {
			font-size: 52rpx;
			font-weight: 700;
			color: rgba(64, 115, 250, 1);
			text-align: left;
			vertical-align: top;
			margin: 14rpx 0 30rpx 0;
		}

		.time {
			font-size: 24rpx;
			font-weight: 400;
			color: rgba(149, 149, 149, 1);
			text-align: left;
			vertical-align: top;

		}

		.tixian {
			right: 0;
			top: 34rpx;
			position: absolute;
			width: 150rpx;
			height: 60rpx;
			border-radius: 200rpx 0px 0px 200rpx;
			background: rgba(255, 141, 26, 1);

			font-size: 26rpx;
			font-weight: 400;
			color: rgba(255, 255, 255, 1);
			text-align: right;
			vertical-align: top;

			i {
				color: rgba(255, 255, 255, 1);
				font-size: 30rpx;
				margin-left: 4rpx;
			}
		}
	}

	.accuDatainfor {
		width: 100%;
		height: 148rpx;
		border-radius: 14rpx;
		background: rgba(255, 255, 255, 1);
		margin-top: 18rpx;

		.infor_item {
			.num {
				font-size: 32rpx;
				font-weight: 550;
				color: rgba(22, 22, 22, 1);
				text-align: center;
				vertical-align: top;
			}

			.tit {
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(149, 149, 149, 1);
				text-align: center;
				vertical-align: top;
			}
		}
	}

	.detail_tit {
		font-size: 32rpx;
		font-weight: 550;
		color: rgba(22, 22, 22, 1);
		text-align: left;
		vertical-align: top;
		margin: 32rpx 0 22rpx 0;
	}

	.detail_item {
		padding: 34rpx;

		.detail_left {
			.tit {
				max-width: 366rpx;
				font-size: 32rpx;
				font-weight: 550;
				color: rgba(0, 0, 0, 1);
				text-align: left;
				vertical-align: top;

			}

			.txt {
				max-width: 366rpx;
				font-size: 22rpx;
				font-weight: 400;
				color: rgba(74, 74, 74, 1);
				text-align: left;
				vertical-align: top;
				margin: 14rpx 0 20rpx 0;
			}

			.time {
				font-size: 22rpx;
				font-weight: 400;
				color: rgba(149, 149, 149, 1);
				text-align: left;
				vertical-align: top;
			}
		}

		.detail_right {
			.prices {
				font-size: 40rpx;
				font-weight: 700;
				color: rgba(255, 80, 36, 1);
				text-align: right;
				vertical-align: top;

			}

			.user_info {
				margin-top: 50rpx;

				.icon {
					border-radius: 100%;
					overflow: hidden;
					width: 34rpx;
					height: 34rpx;
					margin-right: 8rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.tname {
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(22, 22, 22, 1);
					text-align: left;
					vertical-align: top;
				}
			}
		}
	}
</style>